{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<svg height=\"32\" aria-hidden=\"true\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"32\" data-view-component=\"true\" class=\"octicon octicon-mark-github v-align-middle\">\n",
    "    <path d=\"M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z\"></path>\n",
    "</svg> \n",
    "   \n",
    "# Git 操作入门\n",
    "-------------------------------"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 用Git Clone建立本地库\n",
    "+ 语法：git clone 远程地址： 建立目录并建立本地仓库结构\n",
    "+ git clone https://gitee.com/best_tea/python2023.git"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. 用Git init建立本地仓库结构  \n",
    "\n",
    "+ 1 设置全局参数   \n",
    "  - Git config --global  user.name <\"best_tea\">\n",
    "  - Git config --global  user.email <\"best-tea@163.com\">   \n",
    "\n",
    "\n",
    "+ 2 初始化仓库  \n",
    "    - git init 目录名 :**一般是用云端仓库名做目录**\n",
    "    - Git init  < Python2023 >    \n",
    "    建立一个本地目录，并建立git结构     \n",
    "    <img src=./git%E4%BB%93%E5%BA%93%E5%90%8D.jpg width=40%>   \n",
    "    \n",
    "    + 2.1 cd 目录名    \n",
    "    + 2.2 git add .\n",
    "    + 2.3 git commit    \n",
    "+ 或者\n",
    "    - md python2023\n",
    "    - cd python2023\n",
    "    - git init\n",
    "    - git add .\n",
    "    - git commit\n",
    "\n",
    "+ 3 建立远端连接  \n",
    "    - git remote add <别名 > < 云端仓库地址 >\n",
    "    - git remote add origin https://gitee.com/best_tea/Python2023.git\n",
    "\n",
    "\n",
    "+ 4 比较本地库和远端库，拉回远端结构    \n",
    "    - git fetch origin master   \n",
    "\n",
    "\n",
    "+ 5 把远端库拉回本地  \n",
    "    + git pull -u origin master"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Git 使用说明\n",
    "一、 Git 常用命令速查\n",
    "git branch 查看本地所有分支\n",
    "git status 查看当前状态\n",
    "git commit 提交\n",
    "git branch -a 查看所有的分支\n",
    "git branch -r 查看远程所有分支\n",
    "git commit -am \"init\" 提交并且加注释\n",
    "git remote add origin git@192.168.1.119:ndshow\n",
    "git push origin master 将文件给推到服务器上\n",
    "git remote show origin 显示远程库origin里的资源\n",
    "git push origin master:develop\n",
    "git push origin master:hb-dev 将本地库与服务器上的库进行关联\n",
    "git checkout --track origin/dev 切换到远程dev分支\n",
    "git branch -D master develop 删除本地库develop\n",
    "git checkout -b dev 建立一个新的本地分支dev\n",
    "git merge origin/dev 将分支dev与当前分支进行合并\n",
    "git checkout dev 切换到本地dev分支\n",
    "git remote show 查看远程库\n",
    "git add .\n",
    "git rm 文件名(包括路径) 从git中删除指定文件\n",
    "git clone git://github.com/schacon/grit.git 从服务器上将代码给拉下来\n",
    "git config --list 看所有用户\n",
    "git ls-files 看已经被提交的\n",
    "git rm [file name] 删除一个文件\n",
    "git commit -a 提交当前repos的所有的改变\n",
    "git add [file name] 添加一个文件到git index\n",
    "git commit -v 当你用－v参数的时候可以看commit的差异\n",
    "git commit -m \"This is the message describing the commit\" 添加commit信息\n",
    "git commit -a -a是代表add，把所有的change加到git index里然后再commit\n",
    "git commit -a -v 一般提交命令\n",
    "git log 看你commit的日志\n",
    "git diff 查看尚未暂存的更新\n",
    "git rm a.a 移除文件(从暂存区和工作区中删除)\n",
    "git rm --cached a.a 移除文件(只从暂存区中删除)\n",
    "git commit -m \"remove\" 移除文件(从Git中删除)\n",
    "git rm -f a.a 强行移除修改后文件(从暂存区和工作区中删除)\n",
    "git diff --cached 或 $ git diff --staged 查看尚未提交的更新\n",
    "git stash push 将文件给push到一个临时空间中\n",
    "git stash pop 将文件从临时空间pop下来\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "---------------------------------------------------------\n",
    "git remote add origin git@github.com:username/Hello-World.git\n",
    "git push origin master 将本地项目给提交到服务器中\n",
    "-----------------------------------------------------------\n",
    "git pull 本地与服务器端同步\n",
    "-----------------------------------------------------------------\n",
    "git push (远程仓库名) (分支名) 将本地分支推送到服务器上去。\n",
    "git push origin serverfix:awesomebranch\n",
    "------------------------------------------------------------------\n",
    "git fetch 相当于是从远程获取最新版本到本地，不会自动merge\n",
    "git commit -a -m \"log_message\" (-a是提交所有改动，-m是加入log信息) 本地修改同步至服务器端 ：\n",
    "git branch branch_0.1 master 从主分支master创建branch_0.1分支\n",
    "git branch -m branch_0.1 branch_1.0 将branch_0.1重命名为branch_1.0\n",
    "git checkout branch_1.0/master 切换到branch_1.0/master分支\n",
    "du -hs\n",
    "git branch 删除远程branch\n",
    "git push origin :branch_remote_name\n",
    "git branch -r -d branch_remote_name\n",
    "-----------------------------------------------------------\n",
    "初始化版本库，并提交到远程服务器端\n",
    "mkdir WebApp\n",
    "cd WebApp\n",
    "git init 本地初始化\n",
    "touch README\n",
    "git add README 添加文件\n",
    "git commit -m 'first commit'\n",
    "git remote add origin git@github.com:daixu/WebApp.git\n",
    "增加一个远程服务器端\n",
    "上面的命令会增加URL地址为'git@github.com:daixu/WebApp.git'，名称为origin的远程服务器库，以后提交代码的时候只需要使用 origin别名即可\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "python311",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.11.0"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
